package cn.mldn.microcloud.controller;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.mldn.microcloud.service.MySource;

@RestController
@EnableBinding(MySource.class)
public class StreamMessageController {
	
	
	@Autowired
	private MySource source;
	
	
	@PostMapping("/sendByStream")
	public boolean sendByStream(String message) {		
		Message<?> messageObject = MessageBuilder.withPayload("now:"+ new Date()+",message:"+message).build();
		
		return source.output().send(messageObject );
	}
	
}
